import java.util.LinkedList;

public class LinkedDemo01 {
    public static void main(String[] args) {
        //创建新闻标题对象
        NewsTitle news1 = new NewsTitle(1,"狼堡","灰太狼");
        NewsTitle news2 = new NewsTitle(2,"青青草原","喜羊羊");
        NewsTitle news3 = new NewsTitle(3,"羊村","慢羊羊");
        NewsTitle news4 = new NewsTitle(4,"青青草原我最狂","羚羊公主");
        //创建存储新闻标题对象的集合
        LinkedList list = new LinkedList();
        //添加元素
        list.add(news2);
        list.add(news3);
        //首部添加
        list.addFirst(news1);
        //尾部添加
        list.addLast(news4);
        //存储的元素个数
        System.out.println(list.size());   //4
        //获取第一则新闻的标题名和记者
        NewsTitle first = (NewsTitle) list.getFirst();
        System.out.println("采访《"+ first.getTitleName() + "》的记者是" + first.getReporter());
        //获取最后一则新闻的标题名和记者
        NewsTitle last = (NewsTitle)list.getLast();
        System.out.println("采访《" + last.getTitleName() + "》的记者是" + last.getReporter());
        NewsTitle first1 = (NewsTitle) list.getFirst();
        System.out.println(first1.toString());
        System.out.println(first1);
        System.out.println(last);
//        //删除第一个新闻
//        list.removeFirst();
//        //删除最后一个新闻
//        list.removeLast();
        System.out.println(list.toString());
        //遍历所有新闻标题  和记者
//        for (Object obj : list) {
//            NewsTitle newsTitle = (NewsTitle) obj;
//            System.out.println("新闻标题名称是：" + newsTitle.getTitleName() );
//            System.out.println("记者是：" + newsTitle.getReporter());
//        }

    }
}
